import {login} from "@/http/user/user.js";
export let users = {
    namespaced: true,
    state: {

        token: localStorage.getItem('Token'),
        get username(){
            localStorage.getItem('houToken')
        },
        set username(v){
            localStorage.setItem('houToken',v)
        }
    },
    mutations: {
        SET_TOKEN(state, token) {
            localStorage.setItem('Token',token)
            state.token=token
        },
        SET_USERNAME(state, username) {
            state.username = username
        },
        DELETE_TOKEN(state) {
           
            localStorage.removeItem('Token')
        },
        DELETE_USERNAME(state) {
            state.username = ''
        },
    },
    actions: {
        // 登录接口请求
        // 异步的
        async loginFgn({
            commit
        }, obj) {
            let res = await login(obj)
            console.log(obj);
            console.log(res);
            if (res.meta.status == 200) {
                // console.log('登录成功');
                commit("SET_TOKEN", res.data.token)
                commit("SET_USERNAME", res.data.username)
                return Promise.resolve()
            } else {
                // console.log('登录失败');
                return Promise.reject()
            }
        }
    },
}